<template>
  <div>
    <teleport to="#modal-container" v-if="show">
      <div class="modal-container">
         弹窗内容
      </div>
    </teleport>
    <teleport to="#modal-container" v-if="show">
      <div class="modal-container">
         弹窗内容2
      </div>
    </teleport>
    <van-button type="primary" @click="openDialog">弹窗</van-button>
  </div>
</template>

<script>
import {
  ref
} from "vue"
export default {
  name: 'teleport',
  setup() {
    const show = ref(false);

    const openDialog = () => {
      show.value = true;

      setTimeout(() => { // 弹窗的显示时常
        show.value = false;
      }, 50000)
    }

    return {
      show,
      openDialog
    }
  }
}
</script>

<style scoped>
.modal-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 20px;
  background: black;
  border-radius: 40px;
  opacity: 0.7;
  color: white;
  font: normal 16px/20px arial;
}
</style>